// a和b的范围小于2000的时候，直接用递推的方式即可
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 2010;
const int mod = 1e9 + 7;
typedef long long LL;
int c[N][N];

void init()
{
    c[0][0] = 1;
    for (int i = 1; i < N; ++i)
        for (int j = 0; j <= i; ++j)
            if (!j)
                c[i][j] = 1;
            else
                c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    init();
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        cout << c[a][b] << endl;
    }

    return 0;
}
